package com.mall.entity;

import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 订单实体
 * 
 * @author Mall Team
 */
@Data
public class Order {
    
    private Long id;
    private String orderNo;
    private Long userId;
    private BigDecimal totalAmount;
    private BigDecimal paymentAmount;
    private Integer status;
    private String receiverName;
    private String receiverPhone;
    private String receiverAddress;
    private LocalDateTime createTime;
    private LocalDateTime updateTime;
    
    // 关联对象
    private User user;
    private List<OrderItem> orderItems;
    
    /**
     * 订单状态枚举
     */
    public enum Status {
        PENDING_PAYMENT(1, "待付款"),
        PAID(2, "已付款"),
        SHIPPED(3, "已发货"),
        COMPLETED(4, "已完成"),
        CANCELLED(5, "已取消");
        
        private final Integer code;
        private final String desc;
        
        Status(Integer code, String desc) {
            this.code = code;
            this.desc = desc;
        }
        
        public Integer getCode() {
            return code;
        }
        
        public String getDesc() {
            return desc;
        }
        
        public static Status valueOf(Integer code) {
            for (Status status : values()) {
                if (status.getCode().equals(code)) {
                    return status;
                }
            }
            return null;
        }
    }
    
    /**
     * 是否可以取消
     */
    public boolean canCancel() {
        return Status.PENDING_PAYMENT.getCode().equals(this.status);
    }
    
    /**
     * 是否可以支付
     */
    public boolean canPay() {
        return Status.PENDING_PAYMENT.getCode().equals(this.status);
    }
    
    /**
     * 是否可以发货
     */
    public boolean canShip() {
        return Status.PAID.getCode().equals(this.status);
    }
}